package com.salton123.module.api;

import android.app.Application;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * Time:6/21/21 4:13 PM
 * Author:
 * Description:
 */
public class ModuleIncubator implements OnModuleIncubate {
    private List<OnModuleIncubate> modules = new ArrayList<>();

    public void initModules() {
        //插件自动插入代码
    }

    public void registerModule(String className) {
        try {
            Object object = Class.forName(className).getConstructor().newInstance();
            if (object instanceof OnModuleIncubate) {
                modules.add((OnModuleIncubate) object);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void attachBaseContext(@NotNull Application application) {
        for (OnModuleIncubate item : modules) {
            item.attachBaseContext(application);
        }
    }

    @Override
    public void onCreate(@NotNull Application application) {
        for (OnModuleIncubate item : modules) {
            item.onCreate(application);
        }
    }

    @Override
    public void highPriority(@NotNull Application application) {
        for (OnModuleIncubate item : modules) {
            item.highPriority(application);
        }
    }

    @Override
    public void mediumPriority(@NotNull Application application) {
        for (OnModuleIncubate item : modules) {
            item.mediumPriority(application);
        }
    }

    @Override
    public void lowPriority(@NotNull Application application) {
        for (OnModuleIncubate item : modules) {
            item.lowPriority(application);
        }
    }
}
